const router = require("koa-router")();
const UserModel = require("../../models/user");
router.post("/api/register",async ctx=>{
    // console.log(ctx.request.body);
    let {username,password} = ctx.request.body;
    var res = await UserModel.find({name:username});
    if(res.length!=0){
        ctx.body = {
            code:400,
            msg:`用户已存在，请更换用户名！`
        }
    }else{
        var admin = new UserModel({
            name:username,
            password,
            collected:[],
            history:[],
            paid:[],
            cart:[],
            icon:""
        })
        admin.save()
        ctx.body = {
            code:200,
            msg:"注册成功！"
        }
    }
})
module.exports = router;